package com.victor.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.victor.dao.VoteDao;
import com.victor.entity.ContrastRecord;
import com.victor.entity.Publicity;
import com.victor.entity.User;
import com.victor.entity.Vote;
import com.victor.service.VoteService;

@Service
public class VoteServiceImpl implements VoteService {

	@Autowired
	private VoteDao voteDao;

	// 通过openid查询该用户是否已经参加过投票
	@Override
	public User ifJoinVote(String openid) {
		return voteDao.ifJoinVote(openid);
	}

	// 将user信息插入到数据库
	@Override
	public boolean addUserMsg(User user) {
		return voteDao.addUserMsg(user) > 0 ? true : false;
	}

	// 将votes信息插入到数据库
	@Override
	public boolean addVote(Vote vote) {
		return voteDao.addVote(vote) > 0 ? true : false;
	}

	// 通过书名和年龄段查询公示表是否存在该书
	@Override
	public Publicity ifJoinPublicity(String picname, String agegroup) {
		return voteDao.ifJoinPublicity(picname, agegroup);
	}

	// 拿到投票次数,将次数加1,更新数据库
	@Override
	public boolean updPublicity(Publicity publicity) {
		return voteDao.updPublicity(publicity) > 0 ? true : false;
	}

	// 将书名,作者,投票次数1次,和年龄段存入数据库
	@Override
	public boolean insPublicity(Publicity publicity) {
		return voteDao.insPublicity(publicity) > 0 ? true : false;
	}

//	获取投票公示信息
	@Override
	public List<Publicity> getAllPublicity() {
		return voteDao.getAllPublicity();
	}

//	查询参加投票人数
	@Override
	public Integer getTotleUser() {
		return voteDao.getTotleUser();
	}

//	修改榜单信息
	@Override
	public boolean updPublicityContent(Publicity publicity) {
		return voteDao.updPublicityContent(publicity) > 0 ? true : false;
	}

//	获取所有用户
	@Override
	public List<User> getAllUser() {
		return voteDao.getAllUser();
	}

//	通过openid查询user表
	@Override
	public User getUserByOpenid(String openid) {
		return voteDao.getUserByOpenid(openid);
	}

	// 查询传入学校名的人投票了多少
	@Override
	public Integer getSchoolCount(String school) {
		return voteDao.getSchoolCount(school);
	}

	// 查询传入的城市的人投票了多少
	@Override
	public Integer getCityCount(String city) {
		return voteDao.getCityCount(city);
	}

	// 插如对比记录
	@Override
	public int addContrastRecord(ContrastRecord contrastRecord) {
		return voteDao.addContrastRecord(contrastRecord);
	}

	// 查询历史对比列表
	@Override
	public List<ContrastRecord> getContrastRecordList() {
		return voteDao.getContrastRecordList();
	}

	// 通过历史对比列表id查询详情
	@Override
	public ContrastRecord getContrastRecordById(String crid) {
		return voteDao.getContrastRecordById(crid);
	}

}
